clear all

cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/

capture log close

log using "log/POBE_final", replace text

set maxvar 15000


cd /home/almdan/EoC/analysis/revising_citizenship/

use "data/finaldata_revising_citizenship", clear

set more off

keep lopnr btkdpos3 base_inry_year utan_coherent inrar insk_date_sif insk_quart_sif stserv org1 complserv_ch FB2004_coh_ver2 mof_year finish_high_sch moth_schyrs_mod fath_schyrs_mod log_fath_ave_defl_totinc_C log_moth_ave_defl_totinc_C foreign muskkap hals_1-hals_7 perfsight synkap perfhear fyskap lngd mass bodymass intr gkap gvkap gckap pf donor_2230 numb_donor_2230  kund_rtjanst_2015 bet_rtjanst_2015 kund_rtjanst_2016 bet_rtjanst_2016 bethushall_rtjanst_2015 bet_bethushall_rtjanst_2015 bethushall_rtjanst_2016 bet_bethushall_rtjanst_2016 bet_rtjanst kund_el_hush_rtjanst_2015 bet_kund_el_hush_rtjanst_2015 k l r any_vote mof_year mof_date_sif civserv_inskr old20 age_mof_year foreign school_lev6_bef30 lan_trm fodelsear_mof fodelsear inrk mof_month_sif btkd*

*************************************************************
** Merging election 2010 data **
*************************************************************
rename lopnr LopNr
** Change Direcotry **
cd /home/almdan/CMC/

merge 1:1 LopNr using "build/normdata/valdata2010.dta", keepusing(r_2010 l_2010 k_2010 Rostratt_2010) generate(merge_val2010)


drop if merge_val2010==2

** Gen any vote **

gen any_vote_2010=1 if (r_2010==1 | l_2010==1 | k_2010==1)

replace any_vote_2010=0 if any_vote_2010==.

replace any_vote_2010=. if (r_2010==. | l_2010==. | k_2010==.)

label var any_vote_2010 "Voted, Any (2010)"


label values any_vote_2010 rost

tab r_2010
tab l_2010
tab k_2010 

tab any_vote_2010

tab r_2010 any_vote_2010
tab l_2010 any_vote_2010
tab k_2010 any_vote_2010

count if r_2010==.
count if l_2010==.
count if k_2010==.
count if any_vote_2010==.

*************************************************************
** Merging election 2018 data. the 2021 data**
*************************************************************
** Change Direcotry **
cd /home/almdan/CMC/

merge 1:1 LopNr using "build/normdata/valdata2018_2.dta", keepusing(r_2018 l_2018 k_2018 Rostratt_2018) generate(merge_val2018)


drop if merge_val2018==2

** Gen any vote **

gen any_vote_2018=1 if (r_2018==1 | l_2018==1 | k_2018==1)

replace any_vote_2018=0 if any_vote_2018==.

replace any_vote_2018=. if (r_2018==. | l_2018==. | k_2018==.)

label var any_vote_2018 "Voted, Any (2018)"


label values any_vote_2018 rost

tab r_2018
tab l_2018
tab k_2018 

tab any_vote_2018

tab r_2018 any_vote_2018
tab l_2018 any_vote_2018
tab k_2018 any_vote_2018

count if r_2018==.
count if l_2018==.
count if k_2018==.
count if any_vote_2018==.

********************************************************************************
*** Merging new and updated service data ***
*** Create Service variable ***
********************************************************************************

cd /home/almdan/CMC/build/
rename LopNr lopnr
merge 1:1 lopnr using "temp/gu_data_pliktverket_2021_temp", keepusing(org1_ny2021) generate(pliktverket_test)

drop if pliktverket_test==2

********************************************************************************

gen stserv_ny2021=1 if org1_ny2021!=.
replace stserv_ny2021=0 if stserv_ny2021==.
label variable stserv_ny2021 "Started service ny2021"

********************************************************************************
*** Adjusting schoolyears ***
********************************************************************************
replace moth_schyrs_mod=7 if moth_schyrs_mod==6

replace fath_schyrs_mod=7 if fath_schyrs_mod==6

********************************************************************************
*** KEY VARIABLES USED IN THE ANALYSIS ***
********************************************************************************

***************************************************
*** From the NSA test and military service data ***
***************************************************
*** btkd = military occupation code (e.g. xxyyy where x is a letter and y is a number)
*** inrk = test office
*** civserv_inskr = conscripted into civil service (first position in btkd=Q)
*** utan = code for military unit
*** utan_coherent = code for military unit, harmonized across years
*** old20 = indicating wheter a conscript is planned to enter service later that age 20 (inrar - birth year (fodelsear) obtained from SCB)
*** base_inry_year = interaction of inrar and utan_coherent
*** insk_date = date conscripted
*** mof_date_sif = date tested
*** mof_month_sif = test month 
*** insk_quart_sif = quarter of the year when conscripted
*** org1 = The unit in which the conscript entered service (The military service data. Only those who enter service ha an entry in this data set)
*** complserv_ch = indicating whether completed service (defined by receiving grades in the military data)
*** FB2004_coh_ver2 = indicating whether conscript is assigned to a closed unit in 2005 or 2006
*** FB2004_coh_ver2 is defined and created when building the current data set by using the code (what units is described in Ministry of Defence 2004c (see reference list)):

/*
#delimit;
gen FB2004_coh_ver2 = 1 if inrar >= 2005 & insk_date_sif < td(23sep2004) & (
utan_coherent==13 	
| utan_coherent==11 	
| utan_coherent==12	
| utan_coherent==31	
| utan_coherent==28 	
| utan_coherent==24 	
| utan_coherent==25 	
| utan_coherent==23 	
| utan_coherent==37 	
| utan_coherent==26 	
| utan_coherent==16 	
| utan_coherent==17 	
| utan_coherent==18 	
| utan_coherent==19 	
| utan_coherent==3);	

#delimit cr

replace FB2004_coh_ver2=0 if FB2004_coh_ver2==.

label variable FB2004_coh_ver2 "Closed Base"
label values FB2004_coh_ver2 yesno

*/
*** mof_year = test year
*** age_mof_year = age at test year (mof_year - birth year (fodelsear) obtained from SCB)
*** fodelsear_mof = birth year 
*** muskkap = muscle capacity
*** hals1 - hals7 = health category dummies
*** synkap = sight capacity
*** perfhear = hearing capacity
*** fyskap = physical cpacity
*** lngd = height
*** mass = weight
*** bodymass = body mass index (BMI)
*** intr = motivation indicated at the interview
*** gkap = cognitive ability
*** gckap = spatial ability
*** gvkap = verbal ability
*** pf = psychological capacity
*** stserv_ny2021 = indicating whether individual entered service

******************************
*** From Statistics Sweden ***
******************************
*** foreign = foreign background by SCB definition  (computed from utlsvbakgr (LISA register))
*** moth_schyrs_mod = years of schooling mother (computed from SUN2000nivaold (LISA register))
*** fath_schyrs_mod = years of schooling father (computed from SUN2000nivaold (LISA register))
*** finished high school = indicating whether graduated from high school (education register from SCB)
*** school_lev6_bef30 = indicating wheter at least three years of post secondary education before age 30 (computed from SUN2000nivaold (LISA register))
*** fodelsear = birth year (RTB-register from SCB)

******************************
*** Outcomes ***
******************************
*** donor_2230 = inidcating donor between ages 22 and 30
*** numb_donor_2230 = number of years as donor ages 22-30
*** bet_kund_el_hush_rtjanst_2015 = paidfee or belong to a household that has paid the fee to the public broadcasting service
*** l_yyyy = voted in regional election in the year yyyy
*** r_yyyy = voted in the national election in the year yyyy
*** k_yyyy = votet in the municipal election in the year yyyy
*** any_vote_yyyy = voted in any of the three in year yyyy


******************************************************************************
** Creating controls with means imputed and dummy variable indicating missing **
********************************************************************************
gen lngd2 = lngd if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
egen temp = mean(lngd) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
replace lngd2 = temp if lngd == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
label var lngd2 "Height"
drop temp
gen lngd_miss = (lngd == .)

gen finish_high_sch2 = finish_high_sch if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
egen temp = mean(finish_high_sch) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
replace finish_high_sch2 = temp if finish_high_sch==. & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
label var finish_high_sch2 "Finished High School"
drop temp
gen finish_high_sch_miss = (finish_high_sch == .)

gen fath_schyrs_mod2 = fath_schyrs_mod if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
egen temp = mean(fath_schyrs_mod) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
replace fath_schyrs_mod2 = temp if fath_schyrs_mod == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
label var fath_schyrs_mod2 "Father's Schoolyears"
drop temp
gen fath_schyrs_mod_miss = (fath_schyrs_mod == .)

gen moth_schyrs_mod2 = moth_schyrs_mod if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
egen temp = mean(moth_schyrs_mod) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
replace moth_schyrs_mod2 = temp if moth_schyrs_mod == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
label var moth_schyrs_mod2 "Mother's Schoolyears"
drop temp
gen moth_schyrs_mod_miss = (moth_schyrs_mod == .)

gen log_fath_ave_defl_totinc_C2 = log_fath_ave_defl_totinc_C if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
egen temp = mean(log_fath_ave_defl_totinc_C) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
replace log_fath_ave_defl_totinc_C2 = temp if log_fath_ave_defl_totinc_C == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
label var log_fath_ave_defl_totinc_C2 "(Log) Ave. Income Father"
drop temp
gen log_fath_ave_defl_totinc_C_miss = (log_fath_ave_defl_totinc_C == .)

gen log_moth_ave_defl_totinc_C2 = log_moth_ave_defl_totinc_C if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
egen temp = mean(log_moth_ave_defl_totinc_C) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
replace log_moth_ave_defl_totinc_C2 = temp if log_moth_ave_defl_totinc_C == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
label var log_moth_ave_defl_totinc_C2 "(Log) Ave. Income Mother"
drop temp
gen log_moth_ave_defl_totinc_C_miss = (log_moth_ave_defl_totinc_C == .)

gen muskkap2 = muskkap if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
egen temp = mean(muskkap) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
replace muskkap2 = temp if muskkap == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
label var muskkap2 "Muscle Strength"
drop temp
gen muskkap_miss = (muskkap == .)

gen perfsight2 = perfsight if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
egen temp = mean(perfsight) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
replace perfsight2 = temp if perfsight == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
label var perfsight2 "Perfect Eye Sight"
drop temp
gen perfsight_miss = (perfsight == .)

gen synkap2 = synkap if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
egen temp = mean(synkap) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
replace synkap2 = temp if synkap == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
label var synkap2 "Sight Capacity"
drop temp
gen synkap_miss = (synkap == .)

gen perfhear2 = perfhear if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
egen temp = mean(perfhear) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
replace perfhear2 = temp if perfhear == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
label var perfhear2 "Perfect Hearing"
drop temp
gen perfhear_miss = (perfhear == .)

gen fyskap2 = fyskap if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
egen temp = mean(fyskap) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
replace fyskap2 = temp if fyskap == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
label var fyskap2 "Physical Capacity"
drop temp
gen fyskap_miss = (fyskap == .)

gen mass2 = mass if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
egen temp = mean(mass) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
replace mass2 = temp if mass == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
label var mass2 "Weight"
drop temp
gen mass_miss = (mass == .)

gen bodymass2 = bodymass if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
egen temp = mean(bodymass) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
replace bodymass2 = temp if bodymass == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
label var bodymass2 "BMI"
drop temp
gen bodymass_miss = (bodymass == .)

gen gkap2 = gkap if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
egen temp = mean(gkap) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
replace gkap2 = temp if gkap == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
label var gkap2 "Cognitive Ability"
drop temp
gen gkap_miss = (gkap == .)

gen pf2 = pf if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
egen temp = mean(pf) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
replace pf2 = temp if pf == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
label var pf2 "Non-Cognitive Ability"
drop temp
gen pf_miss = (pf == .)

gen gckap2 = gckap if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
egen temp = mean(gckap) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
replace gckap2 = temp if gckap == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
label var gckap2 "Spatial Ability"
drop temp
gen gckap_miss = (gckap == .)

gen gvkap2 = gvkap if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
egen temp = mean(gvkap) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
replace gvkap2 = temp if gvkap == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
label var gvkap2 "Verbal Ability"
drop temp
gen gvkap_miss = (gvkap == .)

gen intr2 = intr if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
egen temp = mean(intr) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
replace intr2 = temp if intr == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
label var intr2 "Motivation"
drop temp
gen intr_miss = (intr == .)

** Health ***


gen hals_12 = hals_1 if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
gen temp = 0 if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
replace hals_12 = temp if hals_1 == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
label var hals_12 "Health Stat.=A"
drop temp
gen hals_1_miss = (hals_1 == .)

gen hals_22 = hals_2 if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
gen temp = 0 if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
replace hals_22 = temp if hals_1 == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0
label var hals_22 "Health Stat.=B"
drop temp
gen hals_2_miss = (hals_2 == .)

** too long variable name ***
gen fee_2015=bet_kund_el_hush_rtjanst_2015

********************************************************************************
*** Figure A.1 A ***
********************************************************************************
cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/

gen age_mof_year_mof=mof_year-fodelsear_mof

label variable age_mof_year_mof "Age at Test Year"


graph bar (percent)  if (inrar > 2001 & insk_date_sif < td(23sep2004)) & civserv_inskr==0 & age_mof_year_mof<22, bar(1, color(gray)) over(age_mof_year_mof) bargap(33) ytitle(Share) saving("graphs/age_test_year", replace) scheme(s1mono) ylabel(0(20)80) yline(0(20)80, lpattern(dash) lcolor(gs12))

graph use "graphs/age_test_year"
graph export "graphs/age_test_year.pdf", replace
graph export "graphs/age_test_year.png", replace
graph export "graphs/age_test_year.tif", replace

********************************************************************************
*** Figure A.1 B ***
********************************************************************************
gen age_planentry_mof=inrar-fodelsear_mof

label variable age_planentry_mof "Age at Plan. Entry"

tab age_planentry_mof if mof_year>2001 & mof_year<2005 & age_mof_year_mof<23 & civserv_inskr!=1


graph bar (percent) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & civserv_inskr==0 & age_mof_year_mof<22 & age_planentry_mof<23, bar(1, color(gray)) over(age_planentry_mof) bargap(33) ytitle(Share)  saving("graphs/age_plan_yearA", replace) scheme(s1mono) ylabel(0(20)80) yline(0(20)80, lpattern(dash) lcolor(gs12))
graph use "graphs/age_plan_yearA"
graph export "graphs/age_plan_yearA.pdf", replace
graph export "graphs/age_plan_yearA.png", replace
graph export "graphs/age_plan_yearA.tif", replace


********************************************************************************
*** Figure 2. Assigned to closed and not closed units, by year and month ***
********************************************************************************
cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/

*** Test year and month *** 
graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0, over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month) over(mof_year) ytitle(Individuals) title("Number of Individuals Assigned to Service") asyvars stack name("freq_assigned_col", replace) nodraw yline(0(1000)2000 ,lpattern(dash) lcolor(gs12)) ylabel(0(1000)2000) ytick(0(500)2000)

graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0, over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month) over(mof_year) ytitle(Share) title("Share Assigned to Service") asyvars stack  percentage name("share_assigned_col", replace) nodraw yline(0(40)100,lpattern(dash) lcolor(gs12)) ylabel(0(40)100) ytick(0(20)100)

grc1leg2 freq_assigned_col share_assigned_col, rows(2) cols(1) saving("graphs/assigned_col", replace) position(6) iscale(*0.9)
graph export "graphs/assigned_col.png", replace
graph export "graphs/assigned_col.tif", replace
graph export "graphs/assigned_col.pdf", replace

graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0, bar(2, color(black)) bar(1, color(gray)) over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month) over(mof_year) ytitle(Individuals) title("Number of Individuals Assigned to Service") asyvars stack name("freq_assigned", replace) nodraw scheme(s1mono) yline(0(1000)2000,lpattern(dash) lcolor(gs12)) ylabel(0(1000)2000) ytick(0(500)2000)

graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0, bar(2, color(black)) bar(1, color(gray)) over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month) over(mof_year) ytitle(Share) title("Share Assigned to Service") asyvars stack  percentage name("share_assigned", replace) nodraw scheme(s1mono) yline(0(40)100, lpattern(dash) lcolor(gs12))  ylabel(0(40)100) ytick(0(20)100)

grc1leg2 freq_assigned share_assigned,rows(2) cols(1) saving("graphs/assigned", replace) position(6) scheme(s1mono) iscale(*0.9)
graph export "graphs/assigned.png", replace
graph export "graphs/assigned.tif", replace
graph export "graphs/assigned.pdf", replace

********************************************************************************
*** Figure A2 and A3. By office region ***
********************************************************************************


graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0 & inrk==1, over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month, label(alternate)) over(mof_year) ytitle(Individuals) title("Test Office Kristianstad") asyvars stack name("freq_assigned_krist_col", replace) nodraw yline(0(200)600 ,lpattern(dash) lcolor(gs12)) ylabel(0(200)600) ytick(0(100)600)
graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0 & inrk==2, over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month, label(alternate)) over(mof_year) ytitle(Individuals) title("Test Office Gothenburg") asyvars stack name("freq_assigned_goth_col", replace) nodraw yline(0(200)600 ,lpattern(dash) lcolor(gs12)) ylabel(0(200)600) ytick(0(100)600)
graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0 & inrk==3, over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month, label(alternate)) over(mof_year) ytitle(Individuals) title("Test Office Stockholm") asyvars stack name("freq_assigned_stock_col", replace) nodraw yline(0(200)600 ,lpattern(dash) lcolor(gs12)) ylabel(0(200)600) ytick(0(100)600)
graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0 & inrk==4, over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month, label(alternate)) over(mof_year) ytitle(Individuals) title("Test Office Karlstad") asyvars stack name("freq_assigned_karl_col", replace) nodraw yline(0(200)600 ,lpattern(dash) lcolor(gs12)) ylabel(0(200)600) ytick(0(100)600)
graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0 & inrk==5, over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month, label(alternate)) over(mof_year) ytitle(Individuals) title("Test Office Östersund") asyvars stack name("freq_assigned_oster_col", replace) nodraw yline(0(200)600 ,lpattern(dash) lcolor(gs12)) ylabel(0(200)600) ytick(0(100)600)
grc1leg2 freq_assigned_krist_col freq_assigned_goth_col freq_assigned_stock_col freq_assigned_karl_col freq_assigned_oster_col,rows(3) cols(2) ycommon iscale(*0.8) saving("graphs/freq_assigned_office_col", replace) position(6)
graph export "graphs/freq_assigned_office_col.png", replace
graph export "graphs/freq_assigned_office_col.tif", replace
graph export "graphs/freq_assigned_office_col.pdf", replace
**

graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0 & inrk==1, bar(2, color(black)) bar(1, color(gray)) over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month, label(alternate)) over(mof_year) ytitle(Individuals) title("Test Office Kristianstad") asyvars stack name("freq_assigned_krist", replace) nodraw scheme(s1mono) yline(0(200)600 ,lpattern(dash) lcolor(gs12)) ylabel(0(200)600) ytick(0(100)600)
graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0 & inrk==2, bar(2, color(black)) bar(1, color(gray)) over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month, label(alternate)) over(mof_year) ytitle(Individuals) title("Test Office Gothenburg") asyvars stack name("freq_assigned_goth", replace) nodraw scheme(s1mono) yline(0(200)600 ,lpattern(dash) lcolor(gs12)) ylabel(0(200)600) ytick(0(100)600)
graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0 & inrk==3, bar(2, color(black)) bar(1, color(gray)) over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month, label(alternate)) over(mof_year) ytitle(Individuals) title("Test Office Stockholm") asyvars stack name("freq_assigned_stock", replace) nodraw scheme(s1mono) yline(0(200)600 ,lpattern(dash) lcolor(gs12)) ylabel(0(200)600) ytick(0(100)600)
graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0 & inrk==4, bar(2, color(black)) bar(1, color(gray)) over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month, label(alternate)) over(mof_year) ytitle(Individuals) title("Test Office Karlstad") asyvars stack name("freq_assigned_karl", replace) nodraw scheme(s1mono) yline(0(200)600 ,lpattern(dash) lcolor(gs12)) ylabel(0(200)600) ytick(0(100)600)
graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0 & inrk==5, bar(2, color(black)) bar(1, color(gray)) over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month, label(alternate)) over(mof_year) ytitle(Individuals) title("Test Office Östersund") asyvars stack name("freq_assigned_oster", replace) nodraw scheme(s1mono) yline(0(200)600 ,lpattern(dash) lcolor(gs12)) ylabel(0(200)600) ytick(0(100)600)
grc1leg2 freq_assigned_krist freq_assigned_goth freq_assigned_stock freq_assigned_karl freq_assigned_oster,rows(3) cols(2) ycommon iscale(*0.8) saving("graphs/freq_assigned_office", replace) position(6) scheme(s1mono)
graph export "graphs/freq_assigned_office.png", replace
graph export "graphs/freq_assigned_office.tif", replace
graph export "graphs/freq_assigned_office.pdf", replace

**

graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0 & inrk==1, over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month, label(alternate)) over(mof_year) ytitle(Share) title("Test Office Kristianstad") asyvars stack percentage name("share_assigned_krist_col", replace) nodraw yline(0(40)100,lpattern(dash) lcolor(gs12)) ylabel(0(40)100) ytick(0(20)100)
graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0 & inrk==2, over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month, label(alternate)) over(mof_year) ytitle(Share) title("Test Office Gothenburg") asyvars stack percentage name("share_assigned_goth_col", replace) nodraw yline(0(40)100,lpattern(dash) lcolor(gs12)) ylabel(0(40)100) ytick(0(20)100)
graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0 & inrk==3, over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month, label(alternate)) over(mof_year) ytitle(Share) title("Test Office Stockholm") asyvars stack percentage name("share_assigned_stock_col", replace) nodraw yline(0(40)100,lpattern(dash) lcolor(gs12)) ylabel(0(40)100) ytick(0(20)100)
graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0 & inrk==4, over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month, label(alternate)) over(mof_year) ytitle(Share) title("Test Office Karlstad") asyvars stack percentage name("share_assigned_karl_col", replace) nodraw yline(0(40)100,lpattern(dash) lcolor(gs12)) ylabel(0(40)100) ytick(0(20)100)
graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0 & inrk==5, over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month, label(alternate)) over(mof_year) ytitle(Share) title("Test Office Östersund") asyvars stack percentage name("share_assigned_oster_col", replace) nodraw yline(0(40)100,lpattern(dash) lcolor(gs12)) ylabel(0(40)100) ytick(0(20)100)
grc1leg2 share_assigned_krist_col share_assigned_goth_col share_assigned_stock_col share_assigned_karl_col share_assigned_oster_col,rows(3) cols(2) ycommon iscale(*0.8) saving("graphs/share_assigned_office_col", replace) position(6)
graph export "graphs/share_assigned_office_col.png", replace
graph export "graphs/share_assigned_office_col.tif", replace
graph export "graphs/share_assigned_office_col.pdf", replace

**

graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0 & inrk==1, bar(2, color(black)) bar(1, color(gray)) over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month, label(alternate)) over(mof_year) ytitle(Share) title("Test Office Kristianstad") asyvars stack percentage name("share_assigned_krist", replace) nodraw scheme(s1mono) yline(0(40)100,lpattern(dash) lcolor(gs12)) ylabel(0(40)100) ytick(0(20)100)
graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0 & inrk==2, bar(2, color(black)) bar(1, color(gray)) over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month, label(alternate)) over(mof_year) ytitle(Share) title("Test Office Gothenburg") asyvars stack percentage name("share_assigned_goth", replace) nodraw scheme(s1mono) yline(0(40)100,lpattern(dash) lcolor(gs12)) ylabel(0(40)100) ytick(0(20)100)
graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0 & inrk==3, bar(2, color(black)) bar(1, color(gray)) over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month, label(alternate)) over(mof_year) ytitle(Share) title("Test Office Stockholm") asyvars stack percentage name("share_assigned_stock", replace) nodraw scheme(s1mono) yline(0(40)100,lpattern(dash) lcolor(gs12)) ylabel(0(40)100) ytick(0(20)100)
graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0 & inrk==4, bar(2, color(black)) bar(1, color(gray)) over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month, label(alternate)) over(mof_year) ytitle(Share) title("Test Office Karlstad") asyvars stack percentage name("share_assigned_karl", replace) nodraw scheme(s1mono) yline(0(40)100,lpattern(dash) lcolor(gs12)) ylabel(0(40)100) ytick(0(20)100)
graph bar (count) if mof_year>2001 & mof_year<2005 & inrar != . & civserv_inskr==0 & inrk==5, bar(2, color(black)) bar(1, color(gray)) over(FB2004_coh_ver2, descending relabel(1 "Non closed unit" 2 "(To-be) closed unit")) over(mof_month, label(alternate)) over(mof_year) ytitle(Share) title("Test Office Östersund") asyvars stack percentage name("share_assigned_oster", replace) nodraw scheme(s1mono) yline(0(40)100,lpattern(dash) lcolor(gs12)) ylabel(0(40)100) ytick(0(20)100)
grc1leg2 share_assigned_krist share_assigned_goth share_assigned_stock share_assigned_karl share_assigned_oster,rows(3) cols(2) ycommon iscale(*0.8) saving("graphs/share_assigned_office", replace) position(6) scheme(s1mono)
graph export "graphs/share_assigned_office.png", replace
graph export "graphs/share_assigned_office.tif", replace
graph export "graphs/share_assigned_office.pdf", replace

********************************************************************************
*** Summary Statistics. Checking missing values ***
********************************************************************************

sum muskkap_miss perfsight_miss synkap_miss perfhear_miss fyskap_miss mass_miss bodymass_miss gkap_miss pf_miss gckap_miss gvkap_miss intr_miss hals_1_miss hals_2_miss finish_high_sch_miss fath_schyrs_mod_miss moth_schyrs_mod_miss log_fath_ave_defl_totinc_C_miss log_moth_ave_defl_totinc_C_miss if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0  & age_mof_year<20 & foreign==0

** only about 1% for father variables and gvkap and gckap and much less for other variables **

** Change Direcotry **
cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/output/

********************************************************************************
*** Summary Statistics. Table 1 and Table A1 ***
********************************************************************************

set more off
eststo clear

eststo: estpost sum stserv_ny2021 complserv_ch FB2004_coh_ver2 mof_year finish_high_sch moth_schyrs_mod fath_schyrs_mod log_fath_ave_defl_totinc_C log_moth_ave_defl_totinc_C foreign muskkap hals_1-hals_2 perfsight synkap perfhear fyskap lngd mass bodymass intr gkap gvkap gckap pf donor_2230 numb_donor_2230 fee_2015 k_2018 l_2018 r_2018 any_vote_2018 k_2010 l_2010 r_2010 any_vote_2010 if (mof_year > 2000 & mof_date_sif < td(23sep2004)) & inrar ==. & civserv_inskr==0 & old20==0 & age_mof_year<20  & foreign==0

eststo: estpost sum stserv_ny2021 complserv_ch FB2004_coh_ver2 mof_year finish_high_sch2 moth_schyrs_mod2 fath_schyrs_mod2 log_fath_ave_defl_totinc_C2 log_moth_ave_defl_totinc_C2 foreign muskkap2 hals_12-hals_22 perfsight2 synkap2 perfhear2 fyskap2 lngd2 mass2 bodymass2 intr2 gkap2 gvkap2 gckap2 pf2 donor_2230 numb_donor_2230 fee_2015 k_2018 l_2018 r_2018 any_vote_2018 k_2010 l_2010 r_2010 any_vote_2010  if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20  & foreign==0

eststo: estpost sum stserv stserv_ny2021 complserv_ch FB2004_coh_ver2 mof_year finish_high_sch2 moth_schyrs_mod2 fath_schyrs_mod2 log_fath_ave_defl_totinc_C2 log_moth_ave_defl_totinc_C2 foreign muskkap2 hals_12-hals_22 perfsight2 synkap2 perfhear2 fyskap2 lngd2 mass2 bodymass2 intr2 gkap2 gvkap2 gckap2 pf2 donor_2230 numb_donor_2230 fee_2015 k_2018 l_2018 r_2018 any_vote_2018 k_2010 l_2010 r_2010 any_vote_2010 if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20  & stserv_ny2021==1 & foreign==0

eststo: estpost sum stserv_ny2021 complserv_ch FB2004_coh_ver2 mof_year finish_high_sch2 moth_schyrs_mod2 fath_schyrs_mod2 log_fath_ave_defl_totinc_C2 log_moth_ave_defl_totinc_C2 foreign muskkap2 hals_12-hals_22 perfsight2 synkap2 perfhear2 fyskap2 lngd2 mass2 bodymass2 intr2 gkap2 gvkap2 gckap2 pf2 donor_2230 numb_donor_2230 fee_2015 k_2018 l_2018 r_2018 any_vote_2018 k_2010 l_2010 r_2010 any_vote_2010 if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20  & stserv_ny2021==0 & foreign==0

eststo: estpost sum stserv_ny2021 complserv_ch FB2004_coh_ver2 mof_year finish_high_sch moth_schyrs_mod fath_schyrs_mod log_fath_ave_defl_totinc_C log_moth_ave_defl_totinc_C foreign muskkap hals_1-hals_2 perfsight synkap perfhear fyskap lngd mass bodymass intr gkap gvkap gckap pf donor_2230 numb_donor_2230 fee_2015 k_2018 l_2018 r_2018 any_vote_2018 k_2010 l_2010 r_2010 any_vote_2010 if (mof_year > 2000 & mof_date_sif < td(23sep2004)) & old20==0 & civserv_inskr==0 & age_mof_year<20  & foreign==0

eststo: estpost sum stserv_ny2021 complserv_ch FB2004_coh_ver2 mof_year finish_high_sch moth_schyrs_mod fath_schyrs_mod log_fath_ave_defl_totinc_C log_moth_ave_defl_totinc_C foreign muskkap hals_1-hals_2 perfsight synkap perfhear fyskap lngd mass bodymass intr gkap gvkap gckap pf donor_2230 numb_donor_2230 fee_2015 k_2018 l_2018 r_2018 any_vote_2018 k_2010 l_2010 r_2010 any_vote_2010 if (mof_year > 2000 & mof_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20  & foreign==0


esttab est5 est1 est6 using "sumstats_nodraft_draft.tex", cell("count mean (fmt(2)) sd (fmt(2))") varwidth(17) modelwidth(5, 7, 5) noobs nonumber nodepvar mtitles("All Tested" "Conscripted = No" "Conscripted = Yes")  refcat(finish_high_sch "Controls, pre-test day:" muskkap "Controls, test-day:" donor_2329 "Outcomes:", nolabel) replace label
esttab est5 est1 est6 using "sumstats_nodraft_draft.rtf", cell("count mean (fmt(2)) sd (fmt(2))") varwidth(17) modelwidth(5, 7, 5) noobs nonumber nodepvar mtitles("All Tested" "Conscripted = No" "Conscripted = Yes")  refcat(finish_high_sch "Controls, pre-test day:" muskkap "Controls, test-day:" donor_2329 "Outcomes:", nolabel) replace label


esttab est2 est3 est4 using "sumstats.tex", cell("count mean (fmt(2)) sd (fmt(2))") varwidth(17) modelwidth(5, 7, 5) noobs nonumber nodepvar mtitles("All Conscripted" "Started. serv. = Yes" "Started. serv. = No") refcat(finish_high_sch "Controls, pre-test day:" muskkap "Controls, test-day:" donor_2329 "Outcomes:", nolabel) replace label
esttab est2 est3 est4 using "sumstats.rtf", cell("count mean (fmt(2)) sd (fmt(2))") varwidth(17) modelwidth(5, 7, 5) noobs nonumber nodepvar mtitles("All Conscripted" "Started. serv. = Yes" "Started. serv. = No") refcat(finish_high_sch "Controls, pre-test day:" muskkap "Controls, test-day:" donor_2329 "Outcomes:", nolabel) replace label

***********************************************************************************
*** Raw comparison of variables by service status ***
*** (to get p-values added in tablenotes Table 1) ***
***********************************************************************************

set more off
eststo clear


local var stserv_ny2021 complserv_ch FB2004_coh_ver2 mof_year finish_high_sch2 moth_schyrs_mod2 fath_schyrs_mod2 log_fath_ave_defl_totinc_C2 log_moth_ave_defl_totinc_C2 foreign muskkap2 hals_12-hals_22 perfsight2 synkap2 perfhear2 fyskap2 lngd2 mass2 bodymass2 intr2 gkap2 gvkap2 gckap2 pf2 donor_2230 numb_donor_2230 fee_2015 k_2018 l_2018 r_2018 any_vote_2018 k_2010 l_2010 r_2010 any_vote_2010

eststo: estpost sum `var' if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & stserv_ny2021==1 & foreign==0
eststo: estpost sum `var' if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & stserv_ny2021==0 & foreign==0
eststo: estpost ttest `var' if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, by(stserv_ny2021)


esttab est1 est2 est3 using "sumstats_by_service.rtf", cell("mean(pattern(1 1 0) label(Mean) fmt(2)) sd(pattern(1 1 0) label(Sd) fmt(2)) b(label(Difference) pattern(0 0 1) fmt(2)) p(label(P-val) fmt(3) pattern(0 0 1))") varwidth(22) modelwidth(7, 5, 7, 5, 10) nonumber nodepvar mtitles("Service = Yes" "Service = No" "") refcat(finish_high_sch "Controls, pre-test day:" muskkap "Controls, test-day:", nolabel) replace label


esttab est1 est2 est3 using "sumstats_by_service.tex", cell("mean(pattern(1 1 0) label(Mean) fmt(2)) sd(pattern(1 1 0) label(Sd) fmt(2)) b(label(Difference) pattern(0 0 1) fmt(2)) p(label(P-val) fmt(2) pattern(0 0 1))")  varwidth(22) modelwidth(7, 5, 7, 5, 10) nonumber nodepvar mtitles("Service = Yes" "Service = No" "") refcat(finish_high_sch "Controls, pre-test day:" muskkap "Controls, test-day:", nolabel) replace label

***********************************************************************************
*** Raw comparison of variables by conscription status ***
*** (to get p-values added in tablenotes Table A.1) ***
***********************************************************************************
gen drafted=(inrar!=.)

set more off
eststo clear

local var stserv_ny2021 complserv_ch FB2004_coh_ver2 mof_year finish_high_sch moth_schyrs_mod fath_schyrs_mod log_fath_ave_defl_totinc_C log_moth_ave_defl_totinc_C foreign muskkap hals_1-hals_2 perfsight synkap perfhear fyskap lngd mass bodymass intr gkap gvkap gckap pf donor_2230 numb_donor_2230 fee_2015 k l r any_vote k_2018 l_2018 r_2018 any_vote_2018 k_2010 l_2010 r_2010 any_vote_2010 

eststo: estpost sum `var' if (mof_year > 2000 & mof_date_sif < td(23sep2004)) & age_mof_year<20 & civserv_inskr==0 & old20==0  & foreign==0 & drafted==1
eststo: estpost sum `var' if (mof_year > 2000 & mof_date_sif < td(23sep2004)) & age_mof_year<20 & civserv_inskr==0 & old20==0  & foreign==0 & drafted==0

eststo: estpost ttest `var' if (mof_year > 2000 & mof_date_sif < td(23sep2004)) & age_mof_year<20 & civserv_inskr==0 & old20==0  & foreign==0, by(drafted)


esttab est1 est2 est3 using "sumstats_by_drafted.rtf", cell("mean(pattern(1 1 0) label(Mean) fmt(2)) sd(pattern(1 1 0) label(Sd) fmt(2)) b(label(Difference) pattern(0 0 1) fmt(2)) p(label(P-val) fmt(3) pattern(0 0 1))") varwidth(22) modelwidth(7, 5, 7, 5, 10) nonumber nodepvar mtitles("Drafted = Yes" "Drafted = No" "") refcat(finish_high_sch "Controls, pre-test day:" muskkap "Controls, test-day:", nolabel) replace label


esttab est1 est2 est3 using "sumstats_by_drafted.tex", cell("mean(pattern(1 1 0) label(Mean) fmt(2)) sd(pattern(1 1 0) label(Sd) fmt(2)) b(label(Difference) pattern(0 0 1) fmt(2)) p(label(P-val) fmt(2) pattern(0 0 1))")  varwidth(22) modelwidth(7, 5, 7, 5, 10) nonumber nodepvar mtitles("Drafted = Yes" "Drafted = No" "") refcat(finish_high_sch "Controls, pre-test day:" muskkap "Controls, test-day:", nolabel) replace label

********************************************************************************
** Table A.2: Raw comparison of variables by reform status**
********************************************************************************

set more off
eststo clear

local var  FB2004_coh_ver2 stserv_ny2021 complserv_ch mof_year finish_high_sch moth_schyrs_mod fath_schyrs_mod muskkap hals_1 hals_2 synkap fyskap lngd mass intr gkap gvkap gckap pf 

eststo: estpost sum `var' if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & FB2004_coh_ver2==1 & foreign==0 
eststo: estpost sum `var' if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & FB2004_coh_ver2==0 & foreign==0
eststo: estpost ttest `var' if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, by(FB2004_coh_ver2)


esttab est1 est2 est3 using "sumstats_by_instr.rtf", cell("mean(pattern(1 1 0) label(Mean) fmt(2)) sd(pattern(1 1 0) label(Sd) fmt(2)) b(label(Difference) pattern(0 0 1) fmt(2)) p(label(P-val) fmt(2) pattern(0 0 1))") varwidth(22) modelwidth(7, 5, 7, 5, 10) nonumber nodepvar mtitles("Closed Unit" "Non-Closed Unit" "") refcat(finish_high_sch "Controls, pre-test day:" muskkap "Controls, test-day:", nolabel) replace label
esttab est1 est2 est3 using "sumstats_by_instr.tex", cell("mean(pattern(1 1 0) label(Mean) fmt(2)) sd(pattern(1 1 0) label(Sd) fmt(2)) b(label(Difference) pattern(0 0 1) fmt(2)) p(label(P-val) fmt(2) pattern(0 0 1))")  varwidth(22) modelwidth(7, 5, 7, 5, 10) nonumber nodepvar mtitles("Closed Unit" "Non-Closed Unit" "") refcat(finish_high_sch "Controls, pre-test day:" muskkap "Controls, test-day:", nolabel) replace label

********************************************************************************
*** Creating service trends in to-be closed and non-closed units ***
*** in order to create Figure 3 ***
********************************************************************************
#delimit;
gen FB2004_coh_trend_ver2 = 1 if 
utan_coherent==13 	
| utan_coherent==11 	
| utan_coherent==12	
| utan_coherent==31	
| utan_coherent==28 	
| utan_coherent==24 	
| utan_coherent==25 	
| utan_coherent==23 	
| utan_coherent==37 	
| utan_coherent==26	
| utan_coherent==16 	
| utan_coherent==17 	
| utan_coherent==18  	
| utan_coherent==19 	
| utan_coherent==3;	

#delimit cr

replace FB2004_coh_trend_ver2=0 if FB2004_coh_trend_ver2==.

label define treatment 0 "Not closed" 1 "Closed"

label variable FB2004_coh_trend_ver2 "Closed base"
label values FB2004_coh_trend_ver2 treatment

tab FB2004_coh_trend_ver2  if (inrar > 2004 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0

tab FB2004_coh_ver2 if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20  & foreign==0

********************************************************************************
*** Figure 3: Trends in service rates ***
********************************************************************************
cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/

preserve
statsby if (inrar > 2000 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, by(inrar FB2004_coh_trend_ver2) clear : ci proportion stserv_ny2021
twoway (connected proportion inrar if FB2004_coh_trend_ver2==1, lpattern(solid) lcolor(black) msymbol(T) mcolor(black))  ( rcap ub lb inrar if FB2004_coh_trend_ver2==1, lcolor(black)) ///
(connected proportion inrar if FB2004_coh_trend_ver2==0, lpattern(solid) lcolor(gray) mcolor(gray)) (rcap ub lb inrar if FB2004_coh_trend_ver2==0, lcolor(gray)), ///
ytitle(Share Started Service) xtitle(Planned Entry Year) legend(order(1 "(To-be) closed unit" 3 "Non closed unit")) name("trends_stserv", replace) nodraw  scheme(s1mono) ytick(0.35(0.05)0.95) yline(0.4(0.1)0.9, lpattern(dash) lcolor(gs12)) ylabel(0.4(0.1)0.9)
restore 

graph display trends_stserv
graph export "graphs/trends_stserv.png", replace
graph export "graphs/trends_stserv.pdf", replace

********************************************************************************
*** Table 2: The first-stage ***
********************************************************************************

cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/output/

local ind_controls muskkap2 pf2 fyskap2 lngd2 mass2 synkap2 finish_high_sch2 intr2 gkap2 gvkap2 gckap2 hals_12 hals_22 muskkap_miss pf_miss fyskap_miss lngd_miss mass_miss synkap_miss finish_high_sch_miss intr_miss gkap_miss gvkap_miss gckap_miss hals_1_miss
local father fath_schyrs_mod2 fath_schyrs_mod_miss 
local mother moth_schyrs_mod2 moth_schyrs_mod_miss 


local 1 i.utan_coherent i.inrar 
local 2 i.utan_coherent i.inrar i.insk_quart_sif 
local 3 i.utan_coherent i.inrar i.insk_quart_sif `ind_controls'
local 4 i.utan_coherent i.inrar i.insk_quart_sif `ind_controls' `mother' `father'

set more off
eststo clear

forvalues n = 1(1)4 {

eststo: reg stserv_ny2021 FB2004_coh_ver2 ``n'' if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0  & age_mof_year<20 & foreign==0, cluster(base_inry_year)

test FB2004_coh
scalar fval=r(F)
estadd scalar fval

}

** Output with no controls shown **
esttab est* using "first_stage_stserv.rtf", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("fval F-statistic" "r2_a Adj. R-squared") indicate("Unit FE=*.utan_coherent" ///
"Plan Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif" ///
"Ind. Controls = muskkap2" "Parent Controls = fath*") ///
addnotes(Clustered standard errors at unit and plan entry year-level.) compress noomitted nocon obslast keep(FB2004_coh_ver2)  replace label

** Output with no controls shown **
esttab est* using "first_stage_stserv.tex", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("fval F-statistic" "r2_a Adj. R-squared") indicate("Unit FE=*.utan_coherent" ///
"Plan Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif" ///
"Ind. Controls = muskkap2" "Parent Controls = fath*") ///
addnotes(Clustered standard errors at unit and plan entry year-level.) compress noomitted nocon obslast keep(FB2004_coh_ver2)  replace label

********************************************************************************
*** Figure 4: Background characteristics by unit assignment ***
********************************************************************************
cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/


preserve
statsby if (inrar > 2000 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, by(inrar FB2004_coh_trend_ver2) clear : ci mean pf
twoway (connected mean inrar if FB2004_coh_trend_ver2==1, lpattern(solid) lcolor(black) msymbol(T) mcolor(black))  ( rcap ub lb inrar if FB2004_coh_trend_ver2==1, lcolor(black)) ///
(connected mean inrar if FB2004_coh_trend_ver2==0, lpattern(solid) lcolor(gray) mcolor(gray)) (rcap ub lb inrar if FB2004_coh_trend_ver2==0, lcolor(gray)), ///
ytitle(Mean) xtitle(Planned Entry Year) title("Psychological Capacity") legend(order(1 "Closed unit" 3 "Non closed unit")) name("trends_pf", replace) nodraw  scheme(s1mono) ytick(4.5(0.5)7.5) yline(5(1)7, lpattern(dash) lcolor(gs12)) ylabel(5(1)7) xlabel(2001 "01" 2002 "02" 2003 "03" 2004 "04" 2005 "05"  2006 "06")
restore 

preserve
statsby if (inrar > 2000 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, by(inrar FB2004_coh_trend_ver2) clear : ci mean fyskap
twoway (connected mean inrar if FB2004_coh_trend_ver2==1, lpattern(solid) lcolor(black) msymbol(T) mcolor(black))  ( rcap ub lb inrar if FB2004_coh_trend_ver2==1, lcolor(black)) ///
(connected mean inrar if FB2004_coh_trend_ver2==0, lpattern(solid) lcolor(gray) mcolor(gray)) (rcap ub lb inrar if FB2004_coh_trend_ver2==0, lcolor(gray)), ///
ytitle(Mean) xtitle(Planned Entry Year) title("Physical Capacity") legend(order(1 "Closed unit" 3 "Non closed unit")) name("trends_fyskap", replace) nodraw  scheme(s1mono) ytick(4.5(0.5)7.5) yline(5(1)7, lpattern(dash) lcolor(gs12)) ylabel(5(1)7) xlabel(2001 "01" 2002 "02" 2003 "03" 2004 "04" 2005 "05"  2006 "06")
restore 


preserve
statsby if (inrar > 2000 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, by(inrar FB2004_coh_trend_ver2) clear : ci proportion finish_high_sch
twoway (connected mean inrar if FB2004_coh_trend_ver2==1, lpattern(solid) lcolor(black) msymbol(T) mcolor(black))  ( rcap ub lb inrar if FB2004_coh_trend_ver2==1, lcolor(black)) ///
(connected mean inrar if FB2004_coh_trend_ver2==0, lpattern(solid) lcolor(gray) mcolor(gray)) (rcap ub lb inrar if FB2004_coh_trend_ver2==0, lcolor(gray)), ///
ytitle(Mean) xtitle(Planned Entry Year) title("Finished High School") legend(order(1 "Closed unit" 3 "Non closed unit")) name("trends_finish_high_sch", replace) nodraw  scheme(s1mono) ytick(0.7(0.05)0.95) yline(0.7(0.1)0.95, lpattern(dash) lcolor(gs12)) ylabel(0.7(0.1)0.9) xlabel(2001 "01" 2002 "02" 2003 "03" 2004 "04" 2005 "05"  2006 "06")
restore 


preserve
statsby if (inrar > 2000 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, by(inrar FB2004_coh_trend_ver2) clear : ci mean gkap
twoway (connected mean inrar if FB2004_coh_trend_ver2==1, lpattern(solid) lcolor(black) msymbol(T) mcolor(black))  ( rcap ub lb inrar if FB2004_coh_trend_ver2==1, lcolor(black)) ///
(connected mean inrar if FB2004_coh_trend_ver2==0, lpattern(solid) lcolor(gray) mcolor(gray)) (rcap ub lb inrar if FB2004_coh_trend_ver2==0, lcolor(gray)), ///
ytitle(Mean) xtitle(Planned Entry Year) title("Cognitive Ability") legend(order(1 "Closed unit" 3 "Non closed unit")) name("trends_gkap", replace) nodraw  scheme(s1mono) ytick(4.5(0.5)7.5) yline(5(1)7, lpattern(dash) lcolor(gs12)) ylabel(5(1)7) xlabel(2001 "01" 2002 "02" 2003 "03" 2004 "04" 2005 "05"  2006 "06")
restore 


preserve
statsby if (inrar > 2000 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, by(inrar FB2004_coh_trend_ver2) clear : ci proportion hals_1
twoway (connected mean inrar if FB2004_coh_trend_ver2==1, lpattern(solid) lcolor(black) msymbol(T) mcolor(black))  ( rcap ub lb inrar if FB2004_coh_trend_ver2==1, lcolor(black)) ///
(connected mean inrar if FB2004_coh_trend_ver2==0, lpattern(solid) lcolor(gray) mcolor(gray)) (rcap ub lb inrar if FB2004_coh_trend_ver2==0, lcolor(gray)), ///
ytitle(Mean) xtitle(Planned Entry Year) title("Health Category A") legend(order(1 "Closed unit" 3 "Non closed unit")) name("trends_hals_1", replace) nodraw  scheme(s1mono) ytick(0.4(0.05)0.8) yline(0.4(0.1)0.8, lpattern(dash) lcolor(gs12)) ylabel(0.4(0.1)0.8) xlabel(2001 "01" 2002 "02" 2003 "03" 2004 "04" 2005 "05"  2006 "06")
restore 

preserve
statsby if (inrar > 2000 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, by(inrar FB2004_coh_trend_ver2) clear : ci mean fath_schyrs_mod
twoway (connected mean inrar if FB2004_coh_trend_ver2==1, lpattern(solid) lcolor(black) msymbol(T) mcolor(black))  ( rcap ub lb inrar if FB2004_coh_trend_ver2==1, lcolor(black)) ///
(connected mean inrar if FB2004_coh_trend_ver2==0, lpattern(solid) lcolor(gray) mcolor(gray)) (rcap ub lb inrar if FB2004_coh_trend_ver2==0, lcolor(gray)), ///
ytitle(Mean) xtitle(Planned Entry Year) title("Father's Schooling") legend(order(1 "Closed unit" 3 "Non closed unit")) name("trends_fath_schyrs_mod", replace) nodraw  scheme(s1mono) ytick(11(0.5)13.5) yline(11(1)13.5, lpattern(dash) lcolor(gs12)) ylabel(11(1)13.5) xlabel(2001 "01" 2002 "02" 2003 "03" 2004 "04" 2005 "05"  2006 "06")
restore 

grc1leg2 trends_gkap trends_pf trends_fyskap trends_hals_1 trends_finish_high_sch trends_fath_schyrs_mod ,rows(2) cols(3) saving("graphs/trends_background", replace) iscale(*0.8) scheme(s1mono)
graph export "graphs/trends_background.png", replace
graph export "graphs/trends_background.tif", replace
graph export "graphs/trends_background.pdf", replace

********************************************************************************
*** Figure A.5. Conditioned on starting service and not starting service ***
********************************************************************************

*** Started ***

preserve
statsby if (inrar > 2000 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, by(inrar FB2004_coh_trend_ver2 stserv_ny2021) clear : ci mean pf
twoway (connected mean inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==1, lpattern(dash) lcolor(black) msymbol(T) mcolor(black))  ( rcap ub lb inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==1, lcolor(black)) ///
(connected mean inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==1, lpattern(dash) lcolor(gray) mcolor(gray)) (rcap ub lb inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==1, lcolor(gray)), ///
ytitle(Mean) xtitle(Planned Entry Year) title("Psychological Capacity") legend(order(1 "Closed unit" 3 "Non closed unit")) name("trends_pf", replace) nodraw  scheme(s1mono) ytick(4.5(0.5)7.5) yline(5(1)7, lpattern(dash) lcolor(gs12)) ylabel(5(1)7) xlabel(2001 "01" 2002 "02" 2003 "03" 2004 "04" 2005 "05"  2006 "06")
restore 

preserve
statsby if (inrar > 2000 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, by(inrar FB2004_coh_trend_ver2 stserv_ny2021) clear : ci mean fyskap
twoway (connected mean inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==1, lpattern(dash) lcolor(black) msymbol(T) mcolor(black))  ( rcap ub lb inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==1, lcolor(black)) ///
(connected mean inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==1, lpattern(dash) lcolor(gray) mcolor(gray)) (rcap ub lb inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==1, lcolor(gray)), ///
ytitle(Mean) xtitle(Planned Entry Year) title("Physical Capacity") legend(order(1 "Closed unit" 3 "Non closed unit")) name("trends_fyskap", replace) nodraw  scheme(s1mono) ytick(4.5(0.5)7.5) yline(5(1)7, lpattern(dash) lcolor(gs12)) ylabel(5(1)7) xlabel(2001 "01" 2002 "02" 2003 "03" 2004 "04" 2005 "05"  2006 "06")
restore 

preserve
statsby if (inrar > 2000 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, by(inrar FB2004_coh_trend_ver2 stserv_ny2021) clear : ci proportion finish_high_sch
twoway (connected mean inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==1, lpattern(dash) lcolor(black) msymbol(T) mcolor(black))  ( rcap ub lb inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==1, lcolor(black)) ///
(connected mean inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==1, lpattern(dash) lcolor(gray) mcolor(gray)) (rcap ub lb inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==1, lcolor(gray)), ///
ytitle(Mean) xtitle(Planned Entry Year) title("Finished High School") legend(order(1 "Closed unit" 3 "Non closed unit")) name("trends_finish_high_sch", replace) nodraw  scheme(s1mono) ytick(0.7(0.05)0.95) yline(0.7(0.1)0.95, lpattern(dash) lcolor(gs12)) ylabel(0.7(0.1)0.9) xlabel(2001 "01" 2002 "02" 2003 "03" 2004 "04" 2005 "05"  2006 "06")
restore 

preserve
statsby if (inrar > 2000 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, by(inrar FB2004_coh_trend_ver2 stserv_ny2021) clear : ci mean gkap
twoway (connected mean inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==1, lpattern(dash) lcolor(black) msymbol(T) mcolor(black))  ( rcap ub lb inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==1, lcolor(black)) ///
(connected mean inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==1, lpattern(dash) lcolor(gray) mcolor(gray)) (rcap ub lb inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==1, lcolor(gray)), ///
ytitle(Mean) xtitle(Planned Entry Year) title("Cognitive Ability") legend(order(1 "Closed unit" 3 "Non closed unit")) name("trends_gkap", replace) nodraw  scheme(s1mono) ytick(4.5(0.5)7.5) yline(5(1)7, lpattern(dash) lcolor(gs12)) ylabel(5(1)7) xlabel(2001 "01" 2002 "02" 2003 "03" 2004 "04" 2005 "05"  2006 "06")
restore 


preserve
statsby if (inrar > 2000 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, by(inrar FB2004_coh_trend_ver2 stserv_ny2021) clear : ci proportion hals_1
twoway (connected mean inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==1, lpattern(dash) lcolor(black) msymbol(T) mcolor(black))  ( rcap ub lb inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==1, lcolor(black)) ///
(connected mean inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==1, lpattern(dash) lcolor(gray) mcolor(gray)) (rcap ub lb inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==1, lcolor(gray)), ///
ytitle(Mean) xtitle(Planned Entry Year) title("Health Category A") legend(order(1 "Closed unit" 3 "Non closed unit")) name("trends_hals_1", replace) nodraw  scheme(s1mono) ytick(0.4(0.05)0.8) yline(0.4(0.1)0.8, lpattern(dash) lcolor(gs12)) ylabel(0.4(0.1)0.8) xlabel(2001 "01" 2002 "02" 2003 "03" 2004 "04" 2005 "05"  2006 "06")
restore 

preserve
statsby if (inrar > 2000 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, by(inrar FB2004_coh_trend_ver2 stserv_ny2021) clear : ci mean fath_schyrs_mod
twoway (connected mean inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==1, lpattern(dash) lcolor(black) msymbol(T) mcolor(black))  ( rcap ub lb inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==1, lcolor(black)) ///
(connected mean inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==1, lpattern(dash) lcolor(gray) mcolor(gray)) (rcap ub lb inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==1, lcolor(gray)), ///
ytitle(Mean) xtitle(Planned Entry Year) title("Father's Schooling") legend(order(1 "Closed unit" 3 "Non closed unit")) name("trends_fath_schyrs_mod", replace) nodraw  scheme(s1mono) ytick(11(0.5)13.5) yline(11(1)13.5, lpattern(dash) lcolor(gs12)) ylabel(11(1)13.5) xlabel(2001 "01" 2002 "02" 2003 "03" 2004 "04" 2005 "05"  2006 "06")
restore 


grc1leg2 trends_gkap trends_pf trends_fyskap trends_hals_1  trends_finish_high_sch trends_fath_schyrs_mod ,rows(2) cols(3) saving("graphs/trends_background_stserv", replace) iscale(*0.8) scheme(s1mono)
graph export "graphs/trends_background_stserv.png", replace
graph export "graphs/trends_background_stserv.tif", replace
graph export "graphs/trends_background_stserv.pdf", replace

*** Not Started ***

preserve
statsby if (inrar > 2000 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, by(inrar FB2004_coh_trend_ver2 stserv_ny2021) clear : ci mean pf
twoway (connected mean inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==0, lpattern(shortdash) lcolor(black) msymbol(T) mcolor(black))  ( rcap ub lb inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==0, lcolor(black)) ///
(connected mean inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==0, lpattern(shortdash) lcolor(gray) mcolor(gray)) (rcap ub lb inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==0, lcolor(gray)), ///
ytitle(Mean) xtitle(Planned Entry Year) title("Psychological Capacity") legend(order(1 "Closed unit" 3 "Non closed unit")) name("trends_pf", replace) nodraw  scheme(s1mono) ytick(4.5(0.5)7.5) yline(5(1)7, lpattern(dash) lcolor(gs12)) ylabel(5(1)7) xlabel(2001 "01" 2002 "02" 2003 "03" 2004 "04" 2005 "05"  2006 "06")
restore 

preserve
statsby if (inrar > 2000 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, by(inrar FB2004_coh_trend_ver2 stserv_ny2021) clear : ci mean fyskap
twoway (connected mean inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==0, lpattern(shortdash) lcolor(black) msymbol(T) mcolor(black))  ( rcap ub lb inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==0, lcolor(black)) ///
(connected mean inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==0, lpattern(shortdash) lcolor(gray) mcolor(gray)) (rcap ub lb inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==0, lcolor(gray)), ///
ytitle(Mean) xtitle(Planned Entry Year) title("Physical Capacity") legend(order(1 "Closed unit" 3 "Non closed unit")) name("trends_fyskap", replace) nodraw  scheme(s1mono) ytick(4.5(0.5)7.5) yline(5(1)7, lpattern(dash) lcolor(gs12)) ylabel(5(1)7) xlabel(2001 "01" 2002 "02" 2003 "03" 2004 "04" 2005 "05"  2006 "06")
restore 


preserve
statsby if (inrar > 2000 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, by(inrar FB2004_coh_trend_ver2 stserv_ny2021) clear : ci proportion finish_high_sch
twoway (connected mean inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==0, lpattern(shortdash) lcolor(black) msymbol(T) mcolor(black))  ( rcap ub lb inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==0, lcolor(black)) ///
(connected mean inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==0, lpattern(shortdash) lcolor(gray) mcolor(gray)) (rcap ub lb inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==0, lcolor(gray)), ///
ytitle(Mean) xtitle(Planned Entry Year) title("Finished High School") legend(order(1 "Closed unit" 3 "Non closed unit")) name("trends_finish_high_sch", replace) nodraw  scheme(s1mono) ytick(0.7(0.05)0.95) yline(0.7(0.1)0.95, lpattern(dash) lcolor(gs12)) ylabel(0.7(0.1)0.9) xlabel(2001 "01" 2002 "02" 2003 "03" 2004 "04" 2005 "05"  2006 "06")
restore 


preserve
statsby if (inrar > 2000 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, by(inrar FB2004_coh_trend_ver2 stserv_ny2021) clear : ci mean gkap
twoway (connected mean inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==0, lpattern(shortdash) lcolor(black) msymbol(T) mcolor(black))  ( rcap ub lb inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==0, lcolor(black)) ///
(connected mean inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==0, lpattern(shortdash) lcolor(gray) mcolor(gray)) (rcap ub lb inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==0, lcolor(gray)), ///
ytitle(Mean) xtitle(Planned Entry Year) title("Cognitive Ability") legend(order(1 "Closed unit" 3 "Non closed unit")) name("trends_gkap", replace) nodraw  scheme(s1mono) ytick(4.5(0.5)7.5) yline(5(1)7, lpattern(dash) lcolor(gs12)) ylabel(5(1)7) xlabel(2001 "01" 2002 "02" 2003 "03" 2004 "04" 2005 "05"  2006 "06")
restore 


preserve
statsby if (inrar > 2000 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, by(inrar FB2004_coh_trend_ver2 stserv_ny2021) clear : ci proportion hals_1
twoway (connected mean inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==0, lpattern(shortdash) lcolor(black) msymbol(T) mcolor(black))  ( rcap ub lb inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==0, lcolor(black)) ///
(connected mean inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==0, lpattern(shortdash) lcolor(gray) mcolor(gray)) (rcap ub lb inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==0, lcolor(gray)), ///
ytitle(Mean) xtitle(Planned Entry Year) title("Health Category A") legend(order(1 "Closed unit" 3 "Non closed unit")) name("trends_hals_1", replace) nodraw  scheme(s1mono)  ytick(0.4(0.05)0.8) yline(0.4(0.1)0.8, lpattern(dash) lcolor(gs12)) ylabel(0.4(0.1)0.8) xlabel(2001 "01" 2002 "02" 2003 "03" 2004 "04" 2005 "05"  2006 "06")
restore 

preserve
statsby if (inrar > 2000 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, by(inrar FB2004_coh_trend_ver2 stserv_ny2021) clear : ci mean fath_schyrs_mod
twoway (connected mean inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==0, lpattern(shortdash) lcolor(black) msymbol(T) mcolor(black))  ( rcap ub lb inrar if FB2004_coh_trend_ver2==1 & stserv_ny2021==0, lcolor(black)) ///
(connected mean inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==0, lpattern(shortdash) lcolor(gray) mcolor(gray)) (rcap ub lb inrar if FB2004_coh_trend_ver2==0 & stserv_ny2021==0, lcolor(gray)), ///
ytitle(Mean) xtitle(Planned Entry Year) title("Father's Schooling") legend(order(1 "Closed unit" 3 "Non closed unit")) name("trends_fath_schyrs_mod", replace) nodraw  scheme(s1mono) ytick(11(0.5)13.5) yline(11(1)13.5, lpattern(dash) lcolor(gs12)) ylabel(11(1)13.5) xlabel(2001 "01" 2002 "02" 2003 "03" 2004 "04" 2005 "05"  2006 "06")
restore 



grc1leg2 trends_gkap trends_pf trends_fyskap trends_hals_1  trends_finish_high_sch trends_fath_schyrs_mod ,rows(2) cols(3) saving("graphs/trends_background_stserv0", replace) iscale(*0.8) scheme(s1mono)
graph export "graphs/trends_background_stserv0.png", replace
graph export "graphs/trends_background_stserv0.tif", replace
graph export "graphs/trends_background_stserv0.pdf", replace


***********************************************************************************
*** Figure 5: Balance Test of Covariates ***
***********************************************************************************

label variable mass "Weight"
label variable lngd "Height"
label variable muskkap "Muscle Strenght"
label variable pf "Psychological Capacity"
label variable gckap "Spatial Ability"
label variable gvkap "Verbal Ability"
label variable intr "Motivation"
label variable fyskap "Physical Capacity"
label variable gkap "Cognitive Ability"
label variable hals_1 "Heath Status A"
label variable hals_2 "Heath Status B"

********************************************************************************
** Standardized **
********************************************************************************
cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/output/

local ind_controls muskkap fyskap lngd mass synkap pf gkap gvkap gckap intr hals_1 hals_2 finish_high_sch
local father fath_schyrs_mod
local mother moth_schyrs_mod


local 1 i.utan_coherent i.inrar i.insk_quart_sif
local 2 i.utan_coherent i.inrar 

forvalues n =  1(1)2 {

set more off 

eststo clear

foreach i in `ind_controls' {

capture egen std_`i'=std(`i') if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0

eststo: qui reg std_`i' FB2004_coh_ver2 ``n'' if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, cluster(base_inry_year) 

estadd ysumm, mean

local `i' : variable label `i'
label variable std_`i' "std. `i' "
}

foreach i in `mother' {

capture  egen std_`i'=std(`i') if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0

eststo: qui reg std_`i' FB2004_coh_ver2 ``n'' if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, cluster(base_inry_year) 

estadd ysumm, mean

local `i' : variable label `i'
label variable std_`i' "std. `i' "
}

foreach i in `father' {

capture egen std_`i'=std(`i') if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0

eststo: qui reg std_`i' FB2004_coh_ver2 ``n'' if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0, cluster(base_inry_year) 

estadd ysumm, mean

local `i' : variable label `i'
label variable std_`i' "std. `i' "
}

esttab est* using "balance_test_`n'_std.csv", se  scalars("ymean Mean Dep. Var.") starlevels(* 0.10 ** 0.05 *** 0.01) keep(FB2004_coh_ver2) abbrev modelwidth(13) compress nocon obslast replace label addnotes(Clustered standard errors at unit and plan entry year-level.)

esttab est1 est2 est3 est4 est5 est6 est7 using "balance_test_`n'A_std.tex", se  starlevels(* 0.10 ** 0.05 *** 0.01) keep(FB2004_coh_ver2) abbrev modelwidth(13) compress nonumber nocon obslast replace label addnotes(Clustered standard errors at unit and plan entry year-level.)

esttab est8 est9 est10  est11 est12 est13 est14 est15 using "balance_test_`n'B_std.tex", se  starlevels(* 0.10 ** 0.05 *** 0.01) keep(FB2004_coh_ver2) abbrev modelwidth(13) nonumber compress nocon obslast replace label addnotes(Clustered standard errors at unit and plan entry year-level.)

esttab est* using "balance_test_`n'_std.rtf", se  scalars("ymean Mean Dep. Var.") starlevels(* 0.10 ** 0.05 *** 0.01) keep(FB2004_coh_ver2) abbrev modelwidth(13) compress nocon obslast replace label addnotes(Clustered standard errors at unit and plan entry year-level.)


coefplot (est1) || (est2)|| (est3) || (est4) || (est5) || (est6) || (est7) ||  ,bylabels("`muskkap'" "`fyskap'" "`lngd'" "`mass'" "`synkap'" "`pf'"  "`gkap'" ) keep(FB2004_coh_ver2) label xline(0, lcolor(black)) xscale(range(-0.15  0.15)) bycoefs xtitle(Point Estimate) byopts(xrescale) nodraw name("balance_test_`n'_plot1", replace) mcolor(gray) ciopts(recast(rcap, lcolor(gray))) scheme(s1mono)

coefplot (est8) || (est9) || (est10) || (est11) || (est12)|| (est13) ||  (est14) || (est15)  || ,bylabels("`gvkap'" "`gckap'"  "`intr'" "`hals_1'" "`hals_2'" "`finish_high_sch'"  "`moth_schyrs_mod'"  "`fath_schyrs_mod'") keep(FB2004_coh_ver2) label xline(0, lcolor(black)) xscale(range(-0.15  0.15)) bycoefs xtitle(Point Estimate) byopts(xrescale) nodraw name("balance_test_`n'_plot2", replace) mcolor(gray) ciopts(recast(rcap, lcolor(gray))) scheme(s1mono)

cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/

graph combine balance_test_`n'_plot1 balance_test_`n'_plot2,rows(1) cols(2) saving("graphs/balance_test_`n'_plot", replace) xcommon scheme(s1mono)
graph export "graphs/balance_test_`n'_plot.png", replace
graph export "graphs/balance_test_`n'_plot.tif", replace
graph export "graphs/balance_test_`n'_plot.pdf", replace

cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/output/
}

************************************************************************************************
*** Table A.3: Test if instrument can predict the predicted outcomes ***
***********************************************************************************************
cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/output/

local ind_controls muskkap2 pf2 fyskap2 lngd2 mass2 synkap2 finish_high_sch2 intr2 gkap2 gvkap2 gckap2 hals_12 hals_22 muskkap_miss pf_miss fyskap_miss lngd_miss mass_miss synkap_miss finish_high_sch_miss intr_miss gkap_miss gvkap_miss gckap_miss hals_1_miss
local father fath_schyrs_mod2 fath_schyrs_mod_miss 
local mother moth_schyrs_mod2 moth_schyrs_mod_miss 

foreach var of varlist donor_2230 numb_donor_2230 fee_2015 any_vote_2010 r_2010 l_2010 k_2010 any_vote_2018 r_2018 l_2018 k_2018 {
	
reg `var' `ind_controls' if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0  & age_mof_year<20 & foreign==0, cluster(base_inry_year)

predict `var'_hat_ind

reg `var' `ind_controls' `mother' `father' if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0  & age_mof_year<20 & foreign==0, cluster(base_inry_year)

predict `var'_hat_all

}

********************************************************************************
eststo clear

foreach var of varlist donor_2230_hat_ind numb_donor_2230_hat_ind fee_2015_hat_ind any_vote_2010_hat_ind r_2010_hat_ind l_2010_hat_ind k_2010_hat_ind any_vote_2018_hat_ind r_2018_hat_ind l_2018_hat_ind k_2018_hat_ind  {

eststo: reg `var' FB2004_coh_ver2 i.utan_coherent i.inrar i.insk_quart_sif if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 , cluster(base_inry_year)


}

esttab est* using "predicted_y_ind.rtf", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("r2_a Adj. R-squared") keep(FB2004_coh_ver2) indicate("Unit FE=*.utan_coherent" ///
"Plan. Entry Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif") ///
abbrev modelwidth(13) compress nocon obslast replace addnotes(Clustered standard errors at unit and plan entry year-level.)

esttab est* using "predicted_y_ind.tex", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("r2_a Adj. R-squared") keep(FB2004_coh_ver2) indicate("Unit FE=*.utan_coherent" ///
"Plan. Entry Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif") ///
abbrev modelwidth(13) compress nocon obslast replace addnotes(Clustered standard errors at unit and plan entry year-level.)


eststo clear

foreach var of varlist donor_2230_hat_all numb_donor_2230_hat_all fee_2015_hat_all any_vote_2010_hat_all r_2010_hat_all l_2010_hat_all k_2010_hat_all any_vote_2018_hat_all r_2018_hat_all l_2018_hat_all k_2018_hat_all {

eststo: reg `var' FB2004_coh_ver2 i.utan_coherent i.inrar i.insk_quart_sif if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 , cluster(base_inry_year)

}

esttab est* using "predicted_y_all.rtf", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("r2_a Adj. R-squared") keep(FB2004_coh_ver2) indicate("Unit FE=*.utan_coherent" ///
"Plan. Entry Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif") ///
abbrev modelwidth(13) compress nocon obslast replace addnotes(Clustered standard errors at unit and plan entry year-level.)

esttab est* using "predicted_y_all.tex", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("r2_a Adj. R-squared") keep(FB2004_coh_ver2) indicate("Unit FE=*.utan_coherent" ///
"Plan. Entry Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif") ///
abbrev modelwidth(13) compress nocon obslast replace addnotes(Clustered standard errors at unit and plan entry year-level.)

**** not including any vote **
eststo clear

foreach var of varlist donor_2230_hat_all numb_donor_2230_hat_all fee_2015_hat_all r_2010_hat_all l_2010_hat_all k_2010_hat_all r_2018_hat_all l_2018_hat_all k_2018_hat_all {

eststo: reg `var' FB2004_coh_ver2 i.utan_coherent i.inrar i.insk_quart_sif if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 , cluster(base_inry_year)

}

esttab est* using "predicted_y_all.rtf", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("r2_a Adj. R-squared") keep(FB2004_coh_ver2) indicate("Unit FE=*.utan_coherent" ///
"Plan. Entry Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif") ///
abbrev modelwidth(13) compress nocon obslast replace addnotes(Clustered standard errors at unit and plan entry year-level.)

esttab est* using "predicted_y_all.tex", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("r2_a Adj. R-squared") keep(FB2004_coh_ver2) indicate("Unit FE=*.utan_coherent" ///
"Plan. Entry Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif") ///
abbrev modelwidth(13) compress nocon obslast replace addnotes(Clustered standard errors at unit and plan entry year-level.)


*** Without imputed mean of x-variables ***


local ind_controls muskkap fyskap lngd mass synkap pf gkap gvkap gckap intr hals_1 hals_2 finish_high_sch  
local father fath_schyrs_mod 
local mother moth_schyrs_mod 

foreach var of varlist donor_2230 numb_donor_2230 fee_2015 any_vote_2010 r_2010  l_2010  k_2010  any_vote_2018 r_2018  l_2018  k_2018 {
	
reg `var' `ind_controls' if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0  & age_mof_year<20 & foreign==0, cluster(base_inry_year)

predict `var'_hat_ind_b

reg `var' `ind_controls' `mother' `father' if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0  & age_mof_year<20 & foreign==0, cluster(base_inry_year)

predict `var'_hat_all_b

}

***
eststo clear

foreach var of varlist donor_2230_hat_ind_b numb_donor_2230_hat_ind_b fee_2015_hat_ind_b any_vote_2010_hat_ind_b r_2010_hat_ind_b l_2010_hat_ind_b k_2010_hat_ind_b any_vote_2018_hat_ind_b r_2018_hat_ind_b l_2018_hat_ind_b k_2018_hat_ind_b  {

eststo: reg `var' FB2004_coh_ver2 i.utan_coherent i.inrar i.insk_quart_sif if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 , cluster(base_inry_year)

}

esttab est* using "predicted_y_ind_b.rtf", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("r2_a Adj. R-squared") keep(FB2004_coh_ver2) indicate("Unit FE=*.utan_coherent" ///
"Plan. Entry Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif") ///
abbrev modelwidth(13) compress nocon obslast replace addnotes(Clustered standard errors at unit and plan entry year-level.)

esttab est* using "predicted_y_ind_b.tex", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("r2_a Adj. R-squared") keep(FB2004_coh_ver2) indicate("Unit FE=*.utan_coherent" ///
"Plan. Entry Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif") ///
abbrev modelwidth(13) compress nocon obslast replace addnotes(Clustered standard errors at unit and plan entry year-level.)


eststo clear

foreach var of varlist donor_2230_hat_all_b numb_donor_2230_hat_all_b fee_2015_hat_all_b any_vote_2010_hat_all_b r_2010_hat_all_b l_2010_hat_all_b k_2010_hat_all_b any_vote_2018_hat_all_b r_2018_hat_all_b l_2018_hat_all_b k_2018_hat_all_b  {

eststo: reg `var' FB2004_coh_ver2 i.utan_coherent i.inrar i.insk_quart_sif if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 , cluster(base_inry_year)

}

esttab est* using "predicted_y_all_b.rtf", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("r2_a Adj. R-squared") keep(FB2004_coh_ver2) indicate("Unit FE=*.utan_coherent" ///
"Plan. Entry Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif") ///
abbrev modelwidth(13) compress nocon obslast replace addnotes(Clustered standard errors at unit and plan entry year-level.)

esttab est* using "predicted_y_all_b.tex", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("r2_a Adj. R-squared") keep(FB2004_coh_ver2) indicate("Unit FE=*.utan_coherent" ///
"Plan. Entry Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif") ///
abbrev modelwidth(13) compress nocon obslast replace addnotes(Clustered standard errors at unit and plan entry year-level.)

********************************************************************************
*** Table A.4: Formal test of paralell trends in outcomes ***

*** (Including more outcomes to better evaluate validity) ***
********************************************************************************
cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/output/

gen placebo2002=(inrar==2002&FB2004_coh_trend_ver2==1)

gen placebo2003=(inrar==2003&FB2004_coh_trend_ver2==1)

gen placebo2004=(inrar==2004&FB2004_coh_trend_ver2==1)

gen FB04_2005 = (inrar==2005&FB2004_coh_trend_ver2==1)

gen FB04_2006 = (inrar==2006&FB2004_coh_trend_ver2==1)


label variable placebo2002 "Cncl. pos. 2002 (Placebo)"
label variable placebo2003 "Cncl. pos. 2003 (Placebo)"
label variable placebo2004 "Cncl. pos. 2004 (Placebo)"
label variable FB04_2005 "Cncl. pos. 2005"
label variable FB04_2006 "Cncl. pos. 2006"

local ind_controls muskkap2 pf2 fyskap2 lngd2 mass2 synkap2 finish_high_sch2 intr2 gkap2 gvkap2 gckap2 hals_12 hals_22 muskkap_miss pf_miss fyskap_miss lngd_miss mass_miss synkap_miss finish_high_sch_miss intr_miss gkap_miss gvkap_miss gckap_miss hals_1_miss
local father fath_schyrs_mod2 fath_schyrs_mod_miss 
local mother moth_schyrs_mod2 moth_schyrs_mod_miss 

eststo clear

	
foreach var of varlist	donor_2230 numb_donor_2230 fee_2015 r_2010 l_2010 k_2010 r_2018 l_2018 k_2018 stserv_ny2021 {
set more off 

eststo: reg `var'  i.utan_coherent i.inrar i.insk_quart_sif placebo2002 placebo2003 FB04_2005 FB04_2006 `ind_controls' `mother' `father' if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 , cluster(base_inry_year)

test placebo2002 placebo2003
scalar p_placebo2002_2003=r(p)
estadd scalar p_placebo2002_2003

}
esttab est* using "paralell_trend_all.rtf", unstack se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("p_placebo2002_2003 P-val F-test placebo2002 placebo2003" "r2_a Adj. R-squared") keep(placebo2002 placebo2003 FB04_2005 FB04_2006 ) indicate("Unit FE=*.utan_coherent" ///
"Cohort FE=*.inrar" ///
"Conscription Quarter FE=*.insk_quart_sif" ///
"Individual Controls = muskkap2" "Parental Controls = fath*") ///
abbrev modelwidth(13) compress nocon obslast replace label addnotes(Clustered standard errors at unit and plan entry year-level.)

esttab est* using "paralell_trend_all.tex", unstack se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("p_placebo2002_2003 P-val F-test placebo2002 placebo2003" "r2_a Adj. R-squared") keep(placebo2002 placebo2003 FB04_2005 FB04_2006 ) indicate("Unit FE=*.utan_coherent" ///
"Cohort FE=*.inrar" ///
"Conscription Quarter FE=*.insk_quart_sif" ///
"Individual Controls = muskkap2" "Parental Controls = fath*") ///
abbrev modelwidth(13) compress nocon obslast replace label addnotes(Clustered standard errors at unit and plan entry year-level.)

*** Withput controls ***

eststo clear

foreach var of varlist donor_2230 numb_donor_2230 fee_2015 r_2010 l_2010 k_2010 r_2018 l_2018 k_2018  stserv_ny2021 {
set more off 

eststo: reg `var'  i.utan_coherent i.inrar i.insk_quart_sif placebo2002 placebo2003 FB04_2005 FB04_2006 if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 , cluster(base_inry_year)

test placebo2002 placebo2003
scalar p_placebo2002_2003=r(p)
estadd scalar p_placebo2002_2003

}
esttab est* using "paralell_trend_all_nocontrols.rtf", unstack se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("p_placebo2002_2003 P-val F-test placebo2002 placebo2003" "r2_a Adj. R-squared") keep(placebo2002 placebo2003 FB04_2005 FB04_2006 ) indicate("Unit FE=*.utan_coherent" ///
"Cohort FE=*.inrar" ///
"Conscription Quarter FE=*.insk_quart_sif") ///
abbrev modelwidth(13) compress nocon obslast replace label addnotes(Clustered standard errors at unit and plan entry year-level.)

esttab est* using "paralell_trend_all_nocontrols.tex", unstack se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("p_placebo2002_2003 P-val F-test placebo2002 placebo2003" "r2_a Adj. R-squared") keep(placebo2002 placebo2003 FB04_2005 FB04_2006 ) indicate("Unit FE=*.utan_coherent" ///
"Cohort FE=*.inrar" ///
"Conscription Quarter FE=*.insk_quart_sif") ///
abbrev modelwidth(13) compress nocon obslast replace label addnotes(Clustered standard errors at unit and plan entry year-level.)

********************************************************************************
*** Table 3: OLS and 2SLS estimated combined ***
********************************************************************************

program iv_ols_regress

	set more off
	
	syntax, dep_var(varname) endo_var(varname) instr(varname) controls1(varlist) controls2(varlist) save_as(name)

	eststo clear


local 1 i.utan_coherent i.inrar i.insk_quart_sif stserv_ny2021
local 2 i.utan_coherent i.inrar i.insk_quart_sif `controls1' stserv_ny2021
local 3 i.utan_coherent i.inrar i.insk_quart_sif `controls1' `controls2' stserv_ny2021

local 4 i.utan_coherent i.inrar i.insk_quart_sif 
local 5 i.utan_coherent i.inrar i.insk_quart_sif `controls1'
local 6 i.utan_coherent i.inrar i.insk_quart_sif `controls1' `controls2'


forvalues n = 1(1)3 {

eststo: reg `dep_var' ``n'' if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0  & age_mof_year<20  & foreign==0, cluster(base_inry_year)
estadd ysumm, mean
}

forvalues n = 4(1)6 {

eststo: ivregress 2sls `dep_var' ``n'' (`endo_var' = `instr') if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0  & age_mof_year<20  & foreign==0, cluster(base_inry_year)
estadd ysumm, mean
}

** Output with no controls shown **
esttab est1 est2 est3 est4 est5 est6 using "results/`save_as'.rtf", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("ymean Mean" "estimator Model") indicate("Unit FE=*.utan_coherent" ///
"Plan Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif" ///
"Ind. Controls = muskkap2" "Parent Controls = fath*") ///
addnotes(Clustered standard errors at unit and plan entry year-level.) compress nocon obslast keep(`endo_var')  replace label


** Output with no controls shown **
esttab est1 est2 est3 est4 est5 est6 using "results/`save_as'.tex", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("ymean Mean" "estimator Model")  indicate("Unit FE=*.utan_coherent" ///
"Plan Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif" ///
"Ind. Controls = muskkap2" "Parent Controls = fath*") ///
addnotes(Clustered standard errors at unit and plan entry year-level.) compress nocon obslast keep(`endo_var')  replace label

** Output with controls shown **
esttab est1 est2 est3 est4 est5 est6 using "results/`save_as'_contr.tex", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("ymean Mean" "estimator Model")  indicate("Unit FE=*.utan_coherent" ///
"Plan Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif") ///
addnotes(Clustered standard errors at unit and plan entry year-level.) compress nocon obslast replace label

end


cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/output/
********************************************************************************
*** Regressions for Table 3 ***
********************************************************************************

local ind_controls muskkap2 pf2 fyskap2 lngd2 mass2 synkap2 finish_high_sch2 intr2 gkap2 gvkap2 gckap2 hals_12 hals_22 muskkap_miss pf_miss fyskap_miss lngd_miss mass_miss synkap_miss finish_high_sch_miss intr_miss gkap_miss gvkap_miss gckap_miss hals_1_miss
local father fath_schyrs_mod2 fath_schyrs_mod_miss 
local mother moth_schyrs_mod2 moth_schyrs_mod_miss 


iv_ols_regress, dep_var(donor_2230) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(donor_2230)


*** Radiotjanst ***
iv_ols_regress, dep_var(fee_2015) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(fee_2015)


*** Election 2018 ***
iv_ols_regress, dep_var(r_2018) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(r_2018)

iv_ols_regress, dep_var(l_2018) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(l_2018)

iv_ols_regress, dep_var(k_2018) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(k_2018)

iv_ols_regress, dep_var(any_vote_2018) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(any_vote_2018)

*** Election 2010 ***

iv_ols_regress, dep_var(r_2010) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(r_2010)

iv_ols_regress, dep_var(l_2010) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(l_2010)

iv_ols_regress, dep_var(k_2010) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(k_2010)

iv_ols_regress, dep_var(any_vote_2010) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(any_vote_2010)

********************************************************************************
*** Table A.5: OLS on the whole tested population ***
********************************************************************************

cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/output/results/ols_tested/

program ols_regress_tested

	set more off
	
	syntax, dep_var(varname) controls1(varlist) controls2(varlist) save_as(name)

	eststo clear

local 1 stserv_ny2021
local 2 i.mof_year i.inrk stserv_ny2021
local 3 i.mof_year i.inrk `controls1' stserv_ny2021
local 4 i.mof_year i.inrk `controls1' `controls2' stserv_ny2021


forvalues n = 1(1)4 {

eststo: reg `dep_var' ``n'' if (mof_year > 2000 & mof_date_sif < td(23sep2004)) & old20==0 & civserv_inskr==0 & age_mof_year<20  & foreign==0, robust
estadd ysumm, mean
}

** Output with no controls shown **
esttab est1 est2 est3 est4 using "`save_as'.rtf", starlevels(* 0.10 ** 0.05 *** 0.01) se scalars("ymean Mean" "r2_a Adj. R-squared" "r2 R-squared") indicate("Test Year FE=*.mof_year" ///
"Test Office FE=*.inrk" ///
"Parental controls=fath*" ///
"Controls = gkap") ///
compress nocon obslast keep(stserv_ny2021)  replace label

** Output with controls shown * *
esttab est1 est2 est3 est4 using "`save_as'_contr.rtf", starlevels(* 0.10 ** 0.05 *** 0.01) se scalars("ymean Mean" "r2_a Adj. R-squared" "r2 R-squared")  indicate("Test Year FE=*.mof_year" ///
"Test Office FE=*.inrk") ///
 compress nocon obslast replace label

** Output with no controls shown **
esttab est1 est2 est3 est4 using "`save_as'.tex", starlevels(* 0.10 ** 0.05 *** 0.01) se scalars("ymean Mean" "r2_a Adj. R-squared" "r2 R-squared")  indicate("Test Year FE=*.mof_year" ///
"Test Office FE=*.inrk" ///
"Parental controls=fath*" ///
"Controls = gkap") ///
compress nocon obslast keep(stserv_ny2021)  replace label

end

********************************************************************************
local ind_controls gkap gvkap gckap finish_high_sch
local father fath_schyrs_mod  
local mother moth_schyrs_mod  


ols_regress_tested, dep_var(donor_2230) controls1(`ind_controls') controls2(`mother' `father') save_as(donor_2230)

ols_regress_tested, dep_var(numb_donor_2230) controls1(`ind_controls') controls2(`mother' `father') save_as(numb_donor_2230)

ols_regress_tested, dep_var(fee_2015) controls1(`ind_controls') controls2(`mother' `father') save_as(fee_2015)


*** Election 2018 ***
ols_regress_tested, dep_var(r_2018) controls1(`ind_controls') controls2(`mother' `father') save_as(r_2018)

ols_regress_tested, dep_var(l_2018) controls1(`ind_controls') controls2(`mother' `father') save_as(l_2018)

ols_regress_tested, dep_var(k_2018)  controls1(`ind_controls') controls2(`mother' `father') save_as(k_2018)

ols_regress_tested, dep_var(any_vote_2018)  controls1(`ind_controls') controls2(`mother' `father') save_as(any_vote_2018)

*** Election 2010, 2021 data ***
ols_regress_tested, dep_var(r_2010) controls1(`ind_controls') controls2(`mother' `father') save_as(r_2010)

ols_regress_tested, dep_var(l_2010) controls1(`ind_controls') controls2(`mother' `father') save_as(l_2010)

ols_regress_tested, dep_var(k_2010)  controls1(`ind_controls') controls2(`mother' `father') save_as(k_2010)

ols_regress_tested, dep_var(any_vote_2010)  controls1(`ind_controls') controls2(`mother' `father') save_as(any_vote_2010)

********************************************************************************
*** Calculating outcome means for sub groups in the tested population ***
*** This is for the "upper bound discussion" in the results section ***
*** Added in footnote 22 ***
********************************************************************************

** all tested **
 sum donor_2230 any_vote_2010 any_vote_2018 fee_2015  if (mof_year > 2000 & mof_year<2005) 
 
** All tested without high school diploma ***
 sum donor_2230 any_vote_2010 any_vote_2018 fee_2015 if (mof_year > 2000 & mof_year<2005) & finish_high_sch==0 & school_lev6_bef30==0
  
** All tested with high school diploma but no university diploma ***
 sum donor_2230 any_vote_2010 any_vote_2018 fee_2015  if (mof_year > 2000 & mof_year<2005) & finish_high_sch==1 & school_lev6_bef30==0
   
** All tested with high university diploma ***
 sum donor_2230 any_vote_2010 any_vote_2018 fee_2015  if (mof_year > 2000 & mof_year<2005) & school_lev6_bef30==1
 
********************************************************************************
*** Hetero-analysis ***
********************************************************************************

*** Generate binary parental education variable ***
*** Parent = high education if more than 12 years of schooling ***

gen fath_high_educ=(fath_schyrs_mod2>12) if !missing(fath_schyrs_mod2)

gen moth_high_educ=(moth_schyrs_mod2>12) if !missing(moth_schyrs_mod2)

tab moth_high_educ moth_schyrs_mod2

tab fath_schyrs_mod2 fath_high_educ 

********************************************************************************

cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/output/results/hetero/
********************************************************************************
*** Balance Test. instrument = controls (Not included in the final paper) ***
********************************************************************************
local ind_controls muskkap2 pf2 fyskap2 lngd2 mass2 synkap2 finish_high_sch2 intr2 gkap2 gvkap2 gckap2 hals_12 hals_22 muskkap_miss pf_miss fyskap_miss lngd_miss mass_miss synkap_miss finish_high_sch_miss intr_miss gkap_miss gvkap_miss gckap_miss hals_1_miss
local father fath_schyrs_mod2 fath_schyrs_mod_miss 
local mother moth_schyrs_mod2 moth_schyrs_mod_miss 

local 1 foreign==0 & fath_high_educ==0 & fath_high_educ!=.
local 2 foreign==0 & fath_high_educ==1  & fath_high_educ!=.
local 3 foreign==0 & btkdpos3=="9" 
local 4 foreign==0 & btkdpos3=="6" | btkdpos3=="7" | btkdpos3=="8"


eststo clear

forvalues n = 1(1)4 {

set more off 

eststo: reg FB2004_coh_ver2 i.utan_coherent i.inrar i.insk_quart_sif `ind_controls' `mother' `father' if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0  & age_mof_year<20  & ``n'', cluster(base_inry_year)

test muskkap2 pf2 fyskap2 lngd2 mass2 synkap2 finish_high_sch2 intr2 gkap2 gvkap2 gckap2 hals_12 hals_22 fath_schyrs_mod2 moth_schyrs_mod2
scalar pall=r(p)
estadd scalar pall
 
}

esttab est* ///
using "balance_ftest_hetero.rtf", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("pall P-val F-test All Controls") indicate("Unit FE=*.utan_coherent" ///
"Plan. Entry Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif") ///
addnotes(Clustered standard errors at unit and plan entry year-level.) compress nocon noomitted obslast replace label

esttab est* ///
using "balance_ftest_hetero.tex", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("pall P-val F-test All Controls") indicate("Unit FE=*.utan_coherent" ///
"Plan. Entry Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif") ///
addnotes(Clustered standard errors at unit and plan entry year-level.) compress nocon noomitted obslast replace label

** Output with no controls shown **
esttab est* using "balance_ftest_hetero_plain.tex", se nonotes starlevels(* 0.10 ** 0.05 *** 0.01) scalars("pall P-val F-test All Controls") ///
compress nocon noobs fragment nodepvar nonumber   replace label

********************************************************************************
*** Table D.1: hetero-analysis, first Stage ***
********************************************************************************
local ind_controls muskkap2 pf2 fyskap2 lngd2 mass2 synkap2 finish_high_sch2 intr2 gkap2 gvkap2 gckap2 hals_12 hals_22 muskkap_miss pf_miss fyskap_miss lngd_miss mass_miss synkap_miss finish_high_sch_miss intr_miss gkap_miss gvkap_miss gckap_miss hals_1_miss
local father fath_schyrs_mod2 fath_schyrs_mod_miss 
local mother moth_schyrs_mod2 moth_schyrs_mod_miss 

local 1 foreign==0 & fath_high_educ==0 & fath_high_educ!=.
local 2 foreign==0 & fath_high_educ==1  & fath_high_educ!=.
local 3 foreign==0 & btkdpos3=="9" 
local 4 foreign==0 & (btkdpos3=="6" | btkdpos3=="7" | btkdpos3=="8")

eststo clear

forvalues n = 1(1)4 {

eststo: reg stserv_ny2021 FB2004_coh_ver2 i.utan_coherent i.inrar i.insk_quart_sif `ind_controls ' `mother' `father' if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & ``n'', cluster(base_inry_year)

test FB2004_coh_ver2
scalar fval=r(F)
estadd scalar fval

}

cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/output/results/hetero/

** Output with no controls shown **
esttab est* using "first_stage_stserv_hetero.rtf", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("fval F-statistic" "r2_a Adj. R-squared") indicate("Unit FE=*.utan_coherent" ///
"Plan Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif" ///
"Ind. Controls = muskkap2" "Parent Controls = fath*") ///
addnotes(Clustered standard errors at unit and plan entry year-level.) compress mtitle("Low" "High" "Private" "Officer") nocon obslast keep(FB2004_coh_ver2)  replace label mgroups("Father's Education" "Service Level", pattern(1 0 1 0))

** Output with no controls shown **
esttab est* using "first_stage_stserv_hetero.tex", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("fval F-statistic" "r2_a Adj. R-squared") indicate("Unit FE=*.utan_coherent" ///
"Plan Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif" ///
"Ind. Controls = muskkap2" "Parent Controls = fath*") ///
addnotes(Clustered standard errors at unit and plan entry year-level.) compress mtitle("Low" "High" "Private" "Officer") nocon obslast keep(FB2004_coh_ver2)  replace label mgroups("Father's Education" "Service Level", pattern(1 0 1 0))

** Output with no controls shown **
esttab est* using "first_stage_stserv_hetero_plain.tex", se nonotes starlevels(* 0.10 ** 0.05 *** 0.01) ///
compress nocon noobs fragment nodepvar nonumber keep(FB2004_coh_ver2)  replace label


********************************************************************************
*** Table A.6: First-stage results across subsamples for complier analysis ***
********************************************************************************

local ind_controls muskkap2 pf2 fyskap2 lngd2 mass2 synkap2 finish_high_sch2 intr2 gkap2 gvkap2 gckap2 hals_12 hals_22 muskkap_miss pf_miss fyskap_miss lngd_miss mass_miss synkap_miss finish_high_sch_miss intr_miss gkap_miss gvkap_miss gckap_miss hals_1_miss
local father fath_schyrs_mod2 fath_schyrs_mod_miss 
local mother moth_schyrs_mod2 moth_schyrs_mod_miss 

local 1 foreign==0 & fath_high_educ==0 & fath_high_educ!=.
local 2 foreign==0 & fath_high_educ==1  & fath_high_educ!=.
local 3 foreign==0 & gkap<6
local 4 foreign==0 & gkap>5
local 5 foreign==0 & finish_high_sch==1
local 6 foreign==0 & finish_high_sch==0

eststo clear

forvalues n = 1(1)6 {

eststo: reg stserv_ny2021 FB2004_coh_ver2 i.utan_coherent i.inrar i.insk_quart_sif if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & ``n'', cluster(base_inry_year)

test FB2004_coh_ver2
scalar fval=r(F)
scalar ratio=_b[FB2004_coh_ver2]/-0.21
estadd scalar fval
estadd scalar ratio
}

cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/output/results/hetero/

** Output with no controls shown **
esttab est* using "first_stage_stserv_hetero_ext_nocontr.rtf", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("fval F-statistic" "r2_a Adj. R-squared"  "ratio Ratio") indicate("Unit FE=*.utan_coherent" ///
"Plan Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif") ///
addnotes(Clustered standard errors at unit and plan entry year-level.) compress mtitle("Low" "High" "Low" "High" "Yes" "No") nocon obslast keep(FB2004_coh_ver2)  replace label mgroups("Father's Education"  "Cognitive ability" "High School" , pattern(1 0 1 0 1 0))

** Output with no controls shown **
esttab est* using "first_stage_stserv_hetero_ext_nocontr.tex", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("fval F-statistic" "r2_a Adj. R-squared"  "ratio Ratio") indicate("Unit FE=*.utan_coherent" ///
"Plan Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif") ///
addnotes(Clustered standard errors at unit and plan entry year-level.) compress mtitle("Low" "High" "Low" "High" "Yes" "No") nocon obslast keep(FB2004_coh_ver2)  replace label mgroups("Father's Education"  "Cognitive ability" "High School" , pattern(1 0 1 0 1 0))


** Output with no controls shown **
esttab est* using "first_stage_stserv_hetero_ext_plain_nocontr.tex", se nonotes starlevels(* 0.10 ** 0.05 *** 0.01) ///
compress nocon noobs fragment nodepvar nonumber keep(FB2004_coh_ver2)  replace label   

********************************************************************************
*** Table D.2: Hetero 2SLS estimates ***
********************************************************************************

program iv_regress

	set more off
	
	syntax, dep_var(varname) endo_var(varname) instr(varname) controls1(varlist) controls2(varlist) save_as(name)

	eststo clear

local 1 foreign==0 & fath_high_educ==0 & fath_high_educ!=.
local 2 foreign==0 & fath_high_educ==1  & fath_high_educ!=.
local 3 foreign==0 & btkdpos3=="9" 
local 4 foreign==0 & btkdpos3=="6" | btkdpos3=="7" | btkdpos3=="8"

eststo clear

forvalues n = 1(1)4 {

eststo: ivregress 2sls `dep_var' i.utan_coherent i.inrar i.insk_quart_sif `controls1' `controls2' (`endo_var' = `instr') if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & ``n'', cluster(base_inry_year)
estadd ysumm, mean
}

** Output with no controls shown **
esttab est* using "results/`save_as'.rtf", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("estimator Model" "ymean Mean") indicate("Unit FE=*.utan_coherent" ///
"Plan Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif" ///
"Ind. Controls = muskkap2" "Parent Controls = fath*") ///
addnotes(Clustered standard errors at unit and plan entry year-level.) compress mtitle("Low" "High" "Private" "Officer")  nocon obslast keep(`endo_var')  replace label mgroups("Father's Education" "Service Level", pattern(1 0 1 0))

esttab est*  using "results/`save_as'.tex", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("estimator Model" "ymean Mean")  indicate("Unit FE=*.utan_coherent" ///
"Plan Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif" ///
"Ind. Controls = muskkap2" "Parent Controls = fath*") ///
addnotes(Clustered standard errors at unit and plan entry year-level.) compress mtitle("Low" "High" "Private" "Officer")  nocon obslast keep(`endo_var')  replace label mgroups("Father's Education" "Service Level", pattern(1 0 1 0))

end

**********************************************************************************
** Hetero regressions for Table D.2. **
**********************************************************************************

cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/output/results/hetero/

local ind_controls muskkap2 pf2 fyskap2 lngd2 mass2 synkap2 finish_high_sch2 intr2 gkap2 gvkap2 gckap2 hals_12 hals_22 muskkap_miss pf_miss fyskap_miss lngd_miss mass_miss synkap_miss finish_high_sch_miss intr_miss gkap_miss gvkap_miss gckap_miss hals_1_miss
local father fath_schyrs_mod2 fath_schyrs_mod_miss 
local mother moth_schyrs_mod2 moth_schyrs_mod_miss 


iv_regress, dep_var(donor_2230) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(donor_2230)

iv_regress, dep_var(fee_2015) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(fee_2015)

*** Election 2018 ***
iv_regress, dep_var(r_2018) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(r_2018)

iv_regress, dep_var(l_2018) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(l_2018)

iv_regress, dep_var(k_2018) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(k_2018)

iv_regress, dep_var(any_vote_2018) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(any_vote_2018)

*** Election 2010 ***
iv_regress, dep_var(r_2010) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(r_2010)

iv_regress, dep_var(l_2010) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(l_2010)

iv_regress, dep_var(k_2010) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(k_2010)

iv_regress, dep_var(any_vote_2010) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(any_vote_2010)

